﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using ZX.HIS.IDAL;
using ZX.HIS.DBUtility;
using System.Text;
//Please add references
namespace ZX.HIS.SQLServerDAL
{
    /// <summary>
    /// 数据访问类:DrugInventory
    /// </summary>
    public partial class DrugInventory : IDrugInventory
    {
        public DrugInventory()
        { }
        #region Depart自写方法

        /// <summary>
        /// 药品库存销售设置表
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public int DrugInventoryAdd(ZX.HIS.Model.DrugInventory mode)
        {
            StringBuilder sql = new System.Text.StringBuilder();
            sql.AppendLine("");

            sql.AppendLine("INSERT INTO [ZX_HISManager].[dbo].[tbDrugInventory]");
            sql.AppendLine("(DrugId,HospitalId,DrugInvThrVal,DrugInvPresPrice,SupplierId,tbDrugShelfCode)");
            sql.AppendLine("VALUES");
            sql.AppendLine("(@DrugId,@HospitalId,@DrugInvThrVal,@DrugInvPresPrice,@SupplierId,@tbDrugShelfCode)");

            SqlParameter[] Parameter ={
                                     new SqlParameter("@DrugId",SqlDbType.Int),
                                     new SqlParameter("@HospitalId",SqlDbType.Int),
                                     new SqlParameter("@DrugInvThrVal",SqlDbType.Int),
                                     new SqlParameter("@DrugInvPresPrice",SqlDbType.Decimal),
                                     new SqlParameter("@SupplierId",SqlDbType.VarChar),
                                     new SqlParameter("@tbDrugShelfCode",SqlDbType.VarChar)
                                     };
            Parameter[0].Value = mode.DrugId;
            Parameter[1].Value = mode.HospitalId;
            Parameter[2].Value = mode.DrugInvThrVal;
            Parameter[3].Value = mode.DrugInvPresPrice;
            Parameter[4].Value = mode.SupplierId;
            Parameter[5].Value = mode.tbDrugShelfCode;
            return SqlDBhelper.ExecuteNonQuery(sql.ToString(), Parameter);
        }

        /// <summary>
        /// 药品库存销售设置表修改返填 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ZX.HIS.Model.DrugInventory DrugInventoryUpdShow(int id)
        {
            string ComTex = "Proc_DrugInventoryModel";
            SqlParameter[] Parameter ={
                                          new SqlParameter("@DrugId",SqlDbType.Int){Value=id}
                                      };
            DataSet ds = SqlDBhelper.RunProcedure(ComTex,Parameter,"db");
            if (ds.Tables[0].Rows.Count > 0) 
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZX.HIS.Model.DrugInventory DataRowToModel(DataRow row)
        {
            ZX.HIS.Model.DrugInventory model = new ZX.HIS.Model.DrugInventory();
            if (row != null)
            {
                if (row["DrugId"] != null && row["DrugId"].ToString() != "")
                {
                    model.DrugId = int.Parse(row["DrugId"].ToString());
                }
                if (row["HospitalId"] != null && row["HospitalId"].ToString() != "")
                {
                    model.HospitalId = int.Parse(row["HospitalId"].ToString());
                }
                if (row["DrugInvThrVal"] != null && row["DrugInvThrVal"].ToString() != "")
                {
                    model.DrugInvThrVal = int.Parse(row["DrugInvThrVal"].ToString());
                }
                if (row["DrugInvPresPrice"] != null && row["DrugInvPresPrice"].ToString() != "")
                {
                    model.DrugInvPresPrice = decimal.Parse(row["DrugInvPresPrice"].ToString());
                }
                if (row["SupplierId"] != null && row["SupplierId"].ToString() != "")
                {
                    model.SupplierId = row["SupplierId"].ToString();
                }
                if (row["tbDrugShelfCode"] != null)
                {
                    model.tbDrugShelfCode = row["tbDrugShelfCode"].ToString();
                }
            }
            return model;
        }
        /// <summary>
        /// 药品库存销售设置表修改
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public int DrugInventoryUpd(ZX.HIS.Model.DrugInventory mode)
        {
            string ComTex = "Proc_DrugInventoryUpt";
            SqlParameter[] Parameter ={
                                     new SqlParameter("@DrugId",SqlDbType.Int){Value=mode.DrugId},
                                     new SqlParameter("@HospitalId",SqlDbType.Int){Value=mode.HospitalId},
                                     new SqlParameter("@DrugInvThrVal",SqlDbType.Int){Value=mode.DrugInvThrVal},
                                     new SqlParameter("@DrugInvPresPrice",SqlDbType.Decimal){Value=mode.DrugInvPresPrice},
                                     new SqlParameter("@SupplierId",SqlDbType.VarChar,200){Value=mode.SupplierId},
                                     new SqlParameter("@tbDrugShelfCode",SqlDbType.VarChar,200){Value=mode.tbDrugShelfCode}
                                     };
            object obj=SqlDBhelper.RunProcedureNonQuery(ComTex, Parameter);
            if(obj!=null)
            {
                return Convert.ToInt32(obj);
            }
            return 0;
        }
        #endregion
        #region  BasicMethod



        ///// <summary>
        ///// 增加一条数据
        ///// </summary>
        //public bool Add(ZX.HIS.Model.DrugInventory model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("insert into tbDrugInventory(");
        //    strSql.Append("DrugId,HospitalId,DrugInvThrVal,DrugInvIsOne,MeasuringUnitName,DrugInvPresPrice,SupplierId,tbDrugShelfCode)");
        //    strSql.Append(" values (");
        //    strSql.Append("@DrugId,@HospitalId,@DrugInvThrVal,@DrugInvIsOne,@MeasuringUnitName,@DrugInvPresPrice,@SupplierId,@tbDrugShelfCode)");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@DrugId", SqlDbType.Int,4),
        //            new SqlParameter("@HospitalId", SqlDbType.Int,4),
        //            new SqlParameter("@DrugInvThrVal", SqlDbType.Int,4),
        //            new SqlParameter("@DrugInvIsOne", SqlDbType.Int,4),
        //            new SqlParameter("@MeasuringUnitName", SqlDbType.Int,4),
        //            new SqlParameter("@DrugInvPresPrice", SqlDbType.Decimal,9),
        //            new SqlParameter("@SupplierId", SqlDbType.Int,4),
        //            new SqlParameter("@tbDrugShelfCode", SqlDbType.VarChar,100)};
        //    parameters[0].Value = model.DrugId;
        //    parameters[1].Value = model.HospitalId;
        //    parameters[2].Value = model.DrugInvThrVal;
        //    parameters[3].Value = model.DrugInvIsOne;
        //    parameters[4].Value = model.MeasuringUnitName;
        //    parameters[5].Value = model.DrugInvPresPrice;
        //    parameters[6].Value = model.SupplierId;
        //    parameters[7].Value = model.tbDrugShelfCode;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        ///// <summary>
        ///// 更新一条数据
        ///// </summary>
        //public bool Update(ZX.HIS.Model.DrugInventory model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("update tbDrugInventory set ");
        //    strSql.Append("DrugId=@DrugId,");
        //    strSql.Append("HospitalId=@HospitalId,");
        //    strSql.Append("DrugInvThrVal=@DrugInvThrVal,");
        //    strSql.Append("DrugInvIsOne=@DrugInvIsOne,");
        //    strSql.Append("MeasuringUnitName=@MeasuringUnitName,");
        //    strSql.Append("DrugInvPresPrice=@DrugInvPresPrice,");
        //    strSql.Append("SupplierId=@SupplierId,");
        //    strSql.Append("tbDrugShelfCode=@tbDrugShelfCode");
        //    strSql.Append(" where ");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@DrugId", SqlDbType.Int,4),
        //            new SqlParameter("@HospitalId", SqlDbType.Int,4),
        //            new SqlParameter("@DrugInvThrVal", SqlDbType.Int,4),
        //            new SqlParameter("@DrugInvIsOne", SqlDbType.Int,4),
        //            new SqlParameter("@MeasuringUnitName", SqlDbType.Int,4),
        //            new SqlParameter("@DrugInvPresPrice", SqlDbType.Decimal,9),
        //            new SqlParameter("@SupplierId", SqlDbType.Int,4),
        //            new SqlParameter("@tbDrugShelfCode", SqlDbType.VarChar,100)};
        //    parameters[0].Value = model.DrugId;
        //    parameters[1].Value = model.HospitalId;
        //    parameters[2].Value = model.DrugInvThrVal;
        //    parameters[3].Value = model.DrugInvIsOne;
        //    parameters[4].Value = model.MeasuringUnitName;
        //    parameters[5].Value = model.DrugInvPresPrice;
        //    parameters[6].Value = model.SupplierId;
        //    parameters[7].Value = model.tbDrugShelfCode;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

        ///// <summary>
        ///// 删除一条数据
        ///// </summary>
        //public bool Delete()
        //{
        //    //该表无主键信息，请自定义主键/条件字段
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("delete from tbDrugInventory ");
        //    strSql.Append(" where ");
        //    SqlParameter[] parameters = {
        //    };

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public ZX.HIS.Model.DrugInventory GetModel()
        //{
        //    //该表无主键信息，请自定义主键/条件字段
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select  top 1 DrugId,HospitalId,DrugInvThrVal,DrugInvIsOne,MeasuringUnitName,DrugInvPresPrice,SupplierId,tbDrugShelfCode from tbDrugInventory ");
        //    strSql.Append(" where ");
        //    SqlParameter[] parameters = {
        //    };

        //    ZX.HIS.Model.DrugInventory model=new ZX.HIS.Model.DrugInventory();
        //    DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
        //    if(ds.Tables[0].Rows.Count>0)
        //    {
        //        return DataRowToModel(ds.Tables[0].Rows[0]);
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public ZX.HIS.Model.DrugInventory DataRowToModel(DataRow row)
        //{
        //    ZX.HIS.Model.DrugInventory model=new ZX.HIS.Model.DrugInventory();
        //    if (row != null)
        //    {
        //        if(row["DrugId"]!=null && row["DrugId"].ToString()!="")
        //        {
        //            model.DrugId=int.Parse(row["DrugId"].ToString());
        //        }
        //        if(row["HospitalId"]!=null && row["HospitalId"].ToString()!="")
        //        {
        //            model.HospitalId=int.Parse(row["HospitalId"].ToString());
        //        }
        //        if(row["DrugInvThrVal"]!=null && row["DrugInvThrVal"].ToString()!="")
        //        {
        //            model.DrugInvThrVal=int.Parse(row["DrugInvThrVal"].ToString());
        //        }
        //        if(row["DrugInvIsOne"]!=null && row["DrugInvIsOne"].ToString()!="")
        //        {
        //            model.DrugInvIsOne=int.Parse(row["DrugInvIsOne"].ToString());
        //        }
        //        if(row["MeasuringUnitName"]!=null && row["MeasuringUnitName"].ToString()!="")
        //        {
        //            model.MeasuringUnitName=int.Parse(row["MeasuringUnitName"].ToString());
        //        }
        //        if(row["DrugInvPresPrice"]!=null && row["DrugInvPresPrice"].ToString()!="")
        //        {
        //            model.DrugInvPresPrice=decimal.Parse(row["DrugInvPresPrice"].ToString());
        //        }
        //        if(row["SupplierId"]!=null && row["SupplierId"].ToString()!="")
        //        {
        //            model.SupplierId=int.Parse(row["SupplierId"].ToString());
        //        }
        //        if(row["tbDrugShelfCode"]!=null)
        //        {
        //            model.tbDrugShelfCode=row["tbDrugShelfCode"].ToString();
        //        }
        //    }
        //    return model;
        //}

        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        //public DataSet GetList(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select DrugId,HospitalId,DrugInvThrVal,DrugInvIsOne,MeasuringUnitName,DrugInvPresPrice,SupplierId,tbDrugShelfCode ");
        //    strSql.Append(" FROM tbDrugInventory ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获得前几行数据
        ///// </summary>
        //public DataSet GetList(int Top,string strWhere,string filedOrder)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select ");
        //    if(Top>0)
        //    {
        //        strSql.Append(" top "+Top.ToString());
        //    }
        //    strSql.Append(" DrugId,HospitalId,DrugInvThrVal,DrugInvIsOne,MeasuringUnitName,DrugInvPresPrice,SupplierId,tbDrugShelfCode ");
        //    strSql.Append(" FROM tbDrugInventory ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    strSql.Append(" order by " + filedOrder);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获取记录总数
        ///// </summary>
        //public int GetRecordCount(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select count(1) FROM tbDrugInventory ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    object obj = DbHelperSQL.GetSingle(strSql.ToString());
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("SELECT * FROM ( ");
        //    strSql.Append(" SELECT ROW_NUMBER() OVER (");
        //    if (!string.IsNullOrEmpty(orderby.Trim()))
        //    {
        //        strSql.Append("order by T." + orderby );
        //    }
        //    else
        //    {
        //        strSql.Append("order by T.DrugFrequencyId desc");
        //    }
        //    strSql.Append(")AS Row, T.*  from tbDrugInventory T ");
        //    if (!string.IsNullOrEmpty(strWhere.Trim()))
        //    {
        //        strSql.Append(" WHERE " + strWhere);
        //    }
        //    strSql.Append(" ) TT");
        //    strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///*
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@tblName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@fldName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@PageSize", SqlDbType.Int),
        //            new SqlParameter("@PageIndex", SqlDbType.Int),
        //            new SqlParameter("@IsReCount", SqlDbType.Bit),
        //            new SqlParameter("@OrderType", SqlDbType.Bit),
        //            new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
        //            };
        //    parameters[0].Value = "tbDrugInventory";
        //    parameters[1].Value = "DrugFrequencyId";
        //    parameters[2].Value = PageSize;
        //    parameters[3].Value = PageIndex;
        //    parameters[4].Value = 0;
        //    parameters[5].Value = 0;
        //    parameters[6].Value = strWhere;	
        //    return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        //}*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

